% 30 Nov 2011

% Run on helpful ratings data alone

% Make data
helpfulX = make_helpful(train(bsxfun(@gt, [train().category], 6)));
helpful_test_x = make_helpful(train(bsxfun(@lt, [train().category], 7)));

% Make into sparse matrices
[i, j, s] = find (helpfulX);
helpfulX = sparse (i, j, s, size(helpfulX, 1), size(helpfulX, 2));
[i, j, s] = find (helpful_test_x);
helpful_test_x = sparse (i, j, s, size(helpful_test_x, 1), size(helpful_test_x, 2));

% Train and test
[results_h, info_h, yhat_h] = lin_liblinear(helpfulX, YcvTrain, ...
  helpful_test_x, YcvTest, 7);

% Calc RMSE
ratings = [2 1 5 4];
[rmse_h, rmseE_h, yhatE_h] = calc_rmse (info_h.vals, ratings, ...
  YcvTest, yhat_h);



%{
%% Multiply helpful ratings by training data to weight the training data

% Make data
helpfulX = make_helpful(train(bsxfun(@gt, [train().category], 6)));
helpful_test_x = make_helpful(train(bsxfun(@lt, [train().category], 7)));

% Make into sparse matrices
[i, j, s] = find (helpfulX);
helpfulX = sparse (i, j, s, size(helpfulX, 1), size(helpfulX, 2));
[i, j, s] = find (helpful_test_x);
helpful_test_x = sparse (i, j, s, size(helpful_test_x, 1), size(helpful_test_x, 2));

% Weight training data with helpful ratings
XcvTrain = bsxfun (@times, XcvTrain, helpfulX);
XcvTest = bsxfun (@times, XcvTest, helpful_test_x);

% Train and test
B = 0.1;
[results_h, info_h, yhat_h] = lin_liblinear(XcvTrain, YcvTrain, ...
  XcvTest, YcvTest, 7, B);

% Calc RMSE
ratings = [2 1 5 4];
[rmse_h, rmseE_h, yhatE_h] = calc_rmse (info_h.vals, ratings, ...
  YcvTest, yhat_h);
%}



%{
% For entire data set

%% Training set (All of X)
helpfulX = make_helpful(train);

%% Test set (All of Xtest)
helpful_test_x = make_helpful(test);


%% This is in run_liblinear_all.m now
% Run lib_linear
%[results.intersect, info, yhat] = lin_liblinear(XhelpTitle, Y, ...
%    XtesthelpTitle, zeros(size(XtesthelpTitle,1),1), 7);

p = exp(info.vals);
p = bsxfun(@times, p, 1./sum(p,2));

ratings = [1 2 4 5];
Yhat_exp = sum(bsxfun(@times, p, ratings),2);
%}


